{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pylab as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Targeting Sharpe ratio as a function of # of bets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "out = []\n",
    "p = 0.55\n",
    "\n",
    "for i in np.arange(1e5):\n",
    "    rnd = np.random.binomial(n=1, p=p)\n",
    "    x = (1 if rnd==1 else -1)\n",
    "    out.append(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.09794, 0.9951923213128203, 0.09841313874970542)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.mean(out), np.std(out), np.mean(out) / np.std(out)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Computing the implied precision"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def binHR(sl, pt, n, tSR):\n",
    "    a = (n + tSR**2) * (pt - sl)**2\n",
    "    b = (2*n*sl - tSR**2*(pt-sl))*(pt-sl)\n",
    "    c = n*sl**2\n",
    "    p = (-b + (b**2 - 4*a*c)**0.5) / (2.*a)\n",
    "    return p"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6844497543078034"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "binHR(-0.025, 0.02, 52, 2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Computing the implied betting frequency"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "def binN(sl, pt, p, tSR):\n",
    "    freq=(tSR*(pt-sl))**2*p*(1-p)/((pt-sl)*p+sl)**2 # possible extraneous\n",
    "    if not np.isclose(binHR(sl,pt,freq,tSR), p):return\n",
    "    return freq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "486.00000000000085"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "binN(-0.025, 0.02, 0.6, 2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Calculating the strategy risk in practice"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "import scipy.stats as ss"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [],
   "source": [
    "def mix_gaussians(mu1, mu2, sigma1, sigma2, prob1, n):\n",
    "    r1 = np.random.normal(mu1, sigma1, size = int(n * prob1))\n",
    "    r2 = np.random.normal(mu2, sigma2, size = int(n) - r1.shape[0])\n",
    "    ret = np.append(r1, r2, axis=0)\n",
    "    np.random.shuffle(ret)\n",
    "    return ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD7CAYAAABzGc+QAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAgAElEQVR4nO3deXxU1f3/8dcnG4GwQ1hkCwiyCLIFBKG4I0sr2qrVaqWtFe0X++tmW1xabetav/26tNbWapW2brgvuCFLQVSUfUcg7AIJYQkQss75/XEnkwxJyGSZTGbyfj4ePnLvuXdmPseJH0/OPYs55xARkegTF+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4Bc4AJ4Y8+dJXUszJTgBedc/nOuW3AFrzf6wb/u+2c2+ucW+4/PgpswNu8PBa/08rqWpmIf6/RkMC7ALvKnO/m1P9So4EDPjSzZWY2zV/W0Tm313+8D+joP46F+le3btFc51v8XQf/LOlWIEbqaWZpwFBgCTH+nZ5UV2ig32s0JPBYNNY5NwyYCEw3s3FlLzrv77OYHB4Uy3UDngBOB4YAe4E/RTacumNmzYFXgZ8653LKXou177SCujbY7zUaEvgeoFuZ867+sqjlnNvj/5kJvI73J9f+kq4R/89M/+2xUP/q1i0q6+yc2++cK3bO+YB/4H2vEOX1NLNEvIT2nHPuNX9xTH6nFdW1IX+v0ZDAvwD6mFlPM0sCrgbeinBMNWZmKWbWouQYGA+sxatTyZP5qcCb/uO3gOv9T/dHAUfK/OkaLapbtw+A8WbWxv/n6nh/WYN20rOJy/G+V/DqebWZNTGznkAf4HOi4HfbzAx4GtjgnPu/Mpdi7jutrK4N+nuN9JPfUP7Be7L9Jd6T3TsiHU8t69IL76n0KmBdSX2AdsBcYDPwEdDWX27A4/66rwHSI12HKur3At6fmYV4fX831KRuwA/wHgptAb4f6XqFWM9/++uxGu8/2M5l7r/DX89NwMQy5Q36dxsYi9c9shpY6f9nUox+p5XVtcF+r5qJKSISpaKhC0VERCqgBC4iEqWUwEVEopQSuIhIlFICFxGJUkrgIiJRSglcRCRKKYGLiESp/w8j4Rtl7AT/uQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "r = mix_gaussians(0.05, -0.1, 0.1, 0.75, 0.85, 2600)\n",
    "\n",
    "plt.figure()\n",
    "plt.plot(r.cumsum())\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [],
   "source": [
    "def probFailure(ret, freq, tSR):\n",
    "    # Derive probability that strategy may fail\n",
    "    rPos, rNeg = ret[ret>0].mean(), ret[ret<=0].mean()\n",
    "    p = ret[ret>0].shape[0] / float(ret.shape[0])\n",
    "    thresP = binHR(rNeg, rPos, freq, tSR)\n",
    "    risk = ss.norm.cdf(thresP, p, p*(1-p)) # approximation to bootstrap\n",
    "    return risk"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.47936643039537374"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "probFailure(r, freq = 260, tSR = 2.0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
